package com.cjx.stars.controller;

import com.cjx.stars.common.MyException;
import com.cjx.stars.common.Response;
import com.cjx.stars.common.ResponseUtils;
import com.cjx.stars.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.cjx.stars.constant.FailMessage.PARAMETER_ABNORMAL;

/**
 * @author cjx
 * @description 信息控制类
 * @createDate 2024/4/21 16:54
 **/
@RestController
@RequestMapping("/message")
@Slf4j
public class MessageController {

    @Resource
    private MessageService messageService;

    @GetMapping
    public Response<?> message() {
        return messageService.hasNewMessage();
    }

    @GetMapping("/blog")
    public Response<?> getBlog(){
        return messageService.getBlog();
    }

    @GetMapping("/blog/num")
    public Response<?> getBlogNum(){
        return messageService.getBlogNum();
    }

    @GetMapping("/like/num")
    public Response<?> getLikeNum(){
        return messageService.getLikeNum();
    }

    @GetMapping("/like")
    public Response<?> pageLikeDetail( int currentPage){
        if (currentPage <= 0 ){
            throw  new MyException(PARAMETER_ABNORMAL);
        }
        return messageService.pageLikeDetail(currentPage);
    }

}
